{% include 'admin/header.html' %}

<body>
  <div class="lyear-layout-web">
    <div class="lyear-layout-container">
      {% include 'admin/nav.html' %}

      <main class="lyear-layout-content">
        <div class="container-fluid">
          <div class="alert alert-success" role="alert">
          <!-- 显示添加成功的提示信息 -->
              此页面用于没加水电表度数。
          {% with messages = get_flashed_messages() %}
            {% if messages %}

                {{ messages[0] }}

            {% endif %}
          {% endwith %}
          </div>
          <!-- 添加水电读数表单 -->
          <div class="card shadow-sm mb-4">
            <div class="card-header">
              <h4 class="card-title mb-0 text-primary">添加水电读数</h4>
            </div>

            <div class="card-body">
              <form method="POST" action="{{ url_for('main.add_meter_reading') }}">
                <!-- 宿舍选择 -->
                <div class="form-group m-4">
                  <label for="dorm_id">选择宿舍</label>
                  <select class="form-control" id="dorm_id" name="dorm_id" required>
                    <option value="">请选择宿舍</option>
                    {% for dorm in dorms %}
                      <option value="{{ dorm.id }}">{{ dorm.name }}</option>
                    {% endfor %}
                  </select>
                </div>

                <!-- 选择月份 -->
                <div class="form-group m-4">
                  <label for="month">选择月份</label>
                  <input type="month" class="form-control w-auto" id="month" name="month" value=" " required>
                </div>

                <!-- 水读数 -->
                <div class="form-group m-4">
                  <label for="water_reading">水读数</label>
                  <input type="number" class="form-control" id="water_reading" name="water_reading" step="any" required>
                </div>

                <!-- 电读数 -->
                <div class="form-group m-4">
                  <label for="electricity_reading">电读数</label>
                  <input type="number" class="form-control" id="electricity_reading" name="electricity_reading" step="any" required>
                </div>

                <!-- 提交按钮 -->
                <button type="submit" class="btn btn-primary">提交</button>
              </form>
            </div>
          </div>

          <!-- 当前月水电读数表格 -->
          <div class="card shadow-sm mb-4">
            <div class="card-header">
              <h4 class="card-title mb-0">当前月份水电读数</h4>
            </div>

            <div class="card-body">
              <table class="table table-striped table-bordered table-hover">
                <thead>
                  <tr>
                    <th>宿舍名称</th>
                    <th>水读数</th>
                    <th>电读数</th>

                  </tr>
                </thead>
                <tbody>
                  {% for dorm in dorms %}
                    <tr>
                      <td>{{ dorm.name }}</td>
                      <td>
                        {% if current_month_readings[dorm.id] %}
                          {{ current_month_readings[dorm.id].water_reading }}
                        {% else %}
                          <span class="text-muted">未添加</span>
                        {% endif %}
                      </td>
                      <td>
                        {% if current_month_readings[dorm.id] %}
                          {{ current_month_readings[dorm.id].electricity_reading }}
                        {% else %}
                          <span class="text-muted">未添加</span>
                        {% endif %}
                      </td>

                    </tr>
                  {% endfor %}
                </tbody>
              </table>
            </div>
          </div>

          <!-- 上月水电读数表格 -->
          <div class="card shadow-sm">
            <div class="card-header">
              <h4 class="card-title mb-0">上月份水电读数</h4>
            </div>

            <div class="card-body">
              <table class="table table-striped table-bordered table-hover">
                <thead>
                  <tr>
                    <th>宿舍名称</th>
                    <th>水读数</th>
                    <th>电读数</th>
                  </tr>
                </thead>
                <tbody>
                  {% for dorm in dorms %}
                    <tr>
                      <td>{{ dorm.name }}</td>
                      <td>
                        {% if last_month_readings[dorm.id] %}
                          {{ last_month_readings[dorm.id].water_reading }}
                        {% else %}
                          <span class="text-muted">未添加</span>
                        {% endif %}
                      </td>
                      <td>
                        {% if last_month_readings[dorm.id] %}
                          {{ last_month_readings[dorm.id].electricity_reading }}
                        {% else %}
                          <span class="text-muted">未添加</span>
                        {% endif %}
                      </td>
                    </tr>
                  {% endfor %}
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </main>
    </div>
  </div>

{% include 'admin/footer.html' %}
</body>
